package org.clever.arkdemo.database;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SqlImportFileCheck {

    public static void main(String[] args) throws IOException {



        File version = new File("/Users/admin/job/database-resource/versions");
        if (!version.exists()) {
            version.createNewFile();
        }


        File dir = new File("/Users/admin/job/database-resource/wanfoudata");

        File[] databaseFiles = dir.listFiles();


        List<String> list = FileUtils.readLines(version);

        Set<String> databaseSet = new HashSet<>(list);

        for (File databaseFile : databaseFiles) {
            if (databaseFile.isDirectory()) {
                String database = databaseFile.getName();
                File[] sqlFiles = databaseFile.listFiles();
                for (File sqlFile : sqlFiles) {
                        /*
wonderful-user-dev/app_user.sql
wonderful-user-dev/user.sql
wonderful-platform-dev/app_user.sql
                         */
                    if (sqlFile.isFile() && sqlFile.getName().endsWith(".sql")) {
                        String key = database + "/" + sqlFile.getName();

                        if (!databaseSet.contains(key)) {
                            if (sqlFile.length() > 1024 * 1024 * 200) {
                                System.out.println(key);
//                              System.out.println("sqlFile=" + key + ",size=" + sqlFile.length() / 1024D + "KB");
                            }

                        }



                    }
                }

            }
        }
    }

    private void importSqlFile(String sqlText, String database, Connection connection) throws SQLException {
//        try (Statement statement = connection.createStatement()) {
//            statement.execute("use " + database);
//            statement.execute(sqlText);
//        }
    }
}
